﻿Option Explicit On
Option Strict On

Imports System.Reflection

Partial Class private_secure_members_manage_MyLists
    Inherits System.Web.UI.Page
    Dim PubTempTable As Data.DataTable
    Dim u As MembershipUser
    Dim txtCustomRefId As String
    Dim txtFirstName As String
    Dim txtLastName As String
    Dim txtHomeEmailAddress As String
    Dim txtWorkEmailAddress As String
    Dim txtMobileNo As String
    Dim txtDateAddedToList As String
    Dim txtIsAdult As Boolean
    Dim txtGender As String
    Dim txtNI_Number As String
    Dim txtSS_Number As String
    Dim txtBirthMonth As Byte
    Dim txtBirthDay As Byte
    Dim txtBirthYear As Short
    Dim txtPostCode As String
    Dim txtHouseNo As String
    Dim txtOccupationNote As String
    Dim txtIsLocal As Boolean
    Dim RecInsertedId As Integer

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        u = Membership.GetUser(HttpContext.Current.User.Identity.Name)
        If Not Page.IsPostBack Then
            If Not Session("eid") Is Nothing AndAlso Not Session("lid") Is Nothing Then

                DropDownList1.SelectedValue = CStr(Session("eid"))
                DropDownList2.DataBind()
                DropDownList2.SelectedValue = CStr(Session("lid"))
                'Label28.Text = (DropDownList1.SelectedValue).DataTextField
                'Label29.Text = DropDownList2.SelectedItem.ToString()
                'Label28.Text = DropDownList1.SelectedItem.ToString()

                DropDownList1.Enabled = False
                DropDownList2.Enabled = False
                btnDDLInsert.Visible = False
                btnDDLUpdate.Visible = False
                btnDDLDelete.Visible = False
                'Label25.Text = DropDownList2.SelectedValue
                'firstRow.Visible = False
                'secondRow.Visible = False
                'thirdRow.Visible = False
                'forthRow.Visible = False
                Dim entitynameTA As New LogginsLogDSTableAdapters.usp_GetPersonEntityListByPersonIdTableAdapter()
                Dim entitynameDT As LogginsLogDS.usp_GetPersonEntityListByPersonIdDataTable
                entitynameDT = entitynameTA.GetData(CType(u.ProviderUserKey, Global.System.Guid?))
                Dim entityname = (From en In entitynameDT.AsEnumerable() Where en.ID = CInt(Session("eid")) Select en).FirstOrDefault()
                Label28.Text = Server.HtmlEncode(entityname.Name)
                Dim targetlistnameTA As New LogginsLogDSTableAdapters.usp_TargetListSelectByEntityIdTableAdapter()
                Dim targetlistnameDT As LogginsLogDS.usp_TargetListSelectByEntityIdDataTable
                targetlistnameDT = targetlistnameTA.GetData(CType(entityname.ID, Integer?))
                Dim listname = (From tl In targetlistnameDT.AsEnumerable() Where tl.ID = CInt(Session("lid")) Select tl.Name).FirstOrDefault()
                Label29.Text = Server.HtmlEncode(listname)
            Else
                'GridView2.Visible = False
                Response.Redirect("~/private/secure_members/manage/MyTargetList.aspx")
            End If

        End If
        'CreateColumnList()

        Try
            If Not Request.QueryString("u") Is Nothing Then

                DropDownList1.SelectedValue = Request.QueryString("u").ToString()
            End If

            'GridView1.DataBind()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub MyEntityODS_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles MyEntityODS.Selecting
        e.InputParameters("UserId") = u.ProviderUserKey
    End Sub

    'Protected Sub Button3_Click(sender As Object, e As System.EventArgs) Handles Button3.Click
    '    'If any of the items have been checked do the following
    '    ' Collect them into a comma separated value and pass it into the proc dbo.usp_TargetListSaveColumnList @TargetListId, @ColumnList like this
    '    ' ALTER PROCEDURE dbo.usp_TargetListSaveColumnList @TargetListId INT, @ColumnList NVARCHAR(1024)
    '    'Dim targetlistcolumnlistTA As New LogginsLogDSTableAdapters.usp_TargetListColumnListSelectTableAdapter()
    '    'Dim targetlistcolumnlistDT As New LogginsLogDS.usp_TargetListColumnListSelectDataTable
    '    'targetlistcolumnlistDT = targetlistcolumnlistTA.GetData(Nothing)
    '    'Dim lkptargetlistcolumnlistTA As New LogginsLogDSTableAdapters.usp_lkp_TargetListColumnListTableAdapter()
    '    'Dim lkptargetlistcolumnlistDT As New LogginsLogDS.usp_lkp_TargetListColumnListDataTable
    '    'lkptargetlistcolumnlistDT = lkptargetlistcolumnlistTA.GetData(Nothing)

    '    'Dim targetlist = From tl In targetlistcolumnlistDT.AsEnumerable() Where tl.TargetListId = CInt(GridView1.SelectedValue.ToString()) Select tl
    '    'Dim targetlistid = (targetlist).FirstOrDefault()
    '    'For Each targetlistRow As LogginsLogDS.usp_TargetListColumnListSelectRow In targetlistcolumnlistDT
    '    '    lkptargetlistcolumnlistTA.Delete(targetlistRow.ColumnId)
    '    'Next
    '    'targetlistcolumnlistTA.Delete((targetlist).FirstOrDefault().Id)
    '    Dim delall As New LogginsLogDSTableAdapters.SPTableAdapter()
    '    delall.usp_TargetListColumnListDeleteByTargetListId(CInt(GridView1.SelectedValue.ToString()))
    '    Dim parameterstring As String = String.Empty
    '    For Each row As GridViewRow In grdSelectedFields.Rows
    '        ' Access the CheckBox
    '        Dim columnname As String = grdSelectedFields.DataKeys(row.RowIndex).Value.ToString()
    '        Dim cb As CheckBox = CType(row.FindControl("chkboxFilled"), CheckBox)
    '        If cb IsNot Nothing AndAlso cb.Checked Then
    '            parameterstring += "," + cb.Text
    '            ''Dim newlkp As Integer = lkptargetlistcolumnlistTA.usp_lkp_TargetListColumnListInsert(cb.Text, True)
    '            'targetlistcolumnlistTA.Insert(DropDownList1.SelectedValue, newlkp, True)
    '        End If
    '    Next
    '    parameterstring = parameterstring.Remove(0, 1)

    '    If Not GridView1.SelectedValue Is Nothing Then
    '        Dim savecolumnsTA As New LogginsLogDSTableAdapters.SPTableAdapter()
    '        savecolumnsTA.usp_TargetListSaveColumnList(CType(GridView1.SelectedValue, Integer?), parameterstring)
    '    Else
    '        Label3.Text = "Please select list from grid first"

    '    End If

    '    Dim x = parameterstring

    'End Sub


    'Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

    '    If e.CommandName = "NewList" Then
    '        'Dim selectedID As Integer = CInt(e.CommandArgument.ToString())
    '        txtName.Text = ""
    '        txtNote.Text = ""

    '        btnInsert.Visible = True
    '        btnUpdate.Visible = False
    '        'hdfSelectedId.Value = CStr(selectedID)
    '        InsertPopupExtender.Show()
    '    ElseIf e.CommandName = "CustomEdit" Then
    '        Dim selectedID As Integer = CInt(e.CommandArgument.ToString())

    '        'Dim selectedID As Integer = CInt(e.CommandArgument.ToString())
    '        Dim targetlistTA As New LogginsLogDSTableAdapters.usp_TargetListByIDTableAdapter()
    '        Dim targetlistDT As LogginsLogDS.usp_TargetListByIDDataTable
    '        targetlistDT = targetlistTA.GetData(selectedID)
    '        For Each targetlistRow As LogginsLogDS.usp_TargetListByIDRow In targetlistDT
    '            txtName.Text = targetlistRow.Name
    '            ddllkpListType.SelectedValue = CStr(targetlistRow.ListTypeId)
    '            txtNote.Text = targetlistRow.Note
    '            hdfSelectedId.Value = CStr(selectedID)
    '        Next
    '        btnInsert.Visible = False
    '        btnUpdate.Visible = True
    '        InsertPopupExtender.Show()

    '    End If


    'End Sub
    Protected Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click
        If txtName.Text = "" Then
            lblInfo.Text = "Please enter the Name of the list"
        Else
            Try
                Dim targetlistTA As New LogginsLogDSTableAdapters.usp_TargetListByIDTableAdapter()
                Dim targetlistDT As LogginsLogDS.usp_TargetListByIDDataTable
                targetlistDT = targetlistTA.GetData(CType(hdfSelectedId.Value, Integer?))
                For Each targetlistRow As LogginsLogDS.usp_TargetListByIDRow In targetlistDT
                    Dim msgref As String
                    Dim billingref As String
                    Dim datecreated As Date
                    If targetlistRow.IsMsgRefNull Then
                        msgref = Nothing
                    Else
                        msgref = targetlistRow.MsgRef
                    End If
                    If targetlistRow.IsBillingRefNull Then
                        billingref = Nothing
                    Else
                        billingref = targetlistRow.MsgRef
                    End If
                    If targetlistRow.IsDateCreatedNull Then
                        datecreated = Nothing
                    Else
                        datecreated = targetlistRow.DateCreated
                    End If
                    'CType(ddllkpListType.SelectedValue, Byte?), txtNote.Text, targetlistRow.SingleUse, targetlistRow.DateCreated, _
                    targetlistTA.Update(CType(hdfSelectedId.Value, Integer?), targetlistRow.EntityId, txtName.Text, msgref, billingref, _
                                        CType(ddllkpListType.SelectedValue, Byte?), txtNote.Text, targetlistRow.SingleUse, Nothing, _
                                        targetlistRow.AutoDiscarded, targetlistRow.DateDiscarded, True)

                Next
            Catch ex As Exception
                Throw ex
            End Try
            Dim sv = DropDownList2.SelectedValue
            DropDownList2.DataBind()
            DropDownList2.SelectedValue = sv
            InsertPopupExtender.Hide()
            'Response.Redirect("~/private/secure_members/manage/Mytargetlist.aspx?u=" & DropDownList1.SelectedValue)
        End If
        'pnlSelectedColumns.Visible = False

    End Sub

    Protected Sub btnInsert_Click(sender As Object, e As System.EventArgs) Handles btnInsert.Click
        InsertTargetListODS.Insert()
        'If txtName.Text = "" Then
        '    lblInfo.Text = "Please enter the Name of the list"
        'Else
        '    Dim justinsertedid As Integer
        '    Dim targetlistTA As New LogginsLogDSTableAdapters.usp_TargetListTableAdapter()
        '    targetlistTA.Insert(CType(DropDownList1.SelectedValue, Integer?), txtName.Text, Nothing, Nothing, CType(ddllkpListType.SelectedValue, Byte?), _
        '                        txtNote.Text, True, DateTime.Now, True, True, True, CType(justinsertedid, Integer?))
        '    GridView1.DataBind()
        '    Response.Redirect("~/private/secure_members/manage/Mytargetlist.aspx?u=" & justinsertedid)
        'End If
        'Dim selection = DropDownList2.SelectedValue

        'DropDownList2.DataBind()
        'DropDownList2.SelectedValue = selection
        'pnlSelectedColumns.Visible = False
    End Sub
    Protected Sub lkpListTypeODS_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles lkpListTypeODS.Selecting
        e.InputParameters("Id") = Nothing
    End Sub



    'Protected Sub grdSelectedFields_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdSelectedFields.RowCommand
    '    If e.CommandName = "GetSelected" Then
    '        Dim parameterstring As String = String.Empty
    '        For Each row As GridViewRow In grdSelectedFields.Rows
    '            ' Access the CheckBox
    '            Dim columnname As String = grdSelectedFields.DataKeys(row.RowIndex).Value.ToString()
    '            Dim cb As CheckBox = CType(row.FindControl("chkFilled"), CheckBox)
    '            If cb IsNot Nothing AndAlso cb.Checked Then
    '                parameterstring += "," + cb.Text
    '                ''Dim newlkp As Integer = lkptargetlistcolumnlistTA.usp_lkp_TargetListColumnListInsert(cb.Text, True)
    '                'targetlistcolumnlistTA.Insert(DropDownList1.SelectedValue, newlkp, True)
    '            End If

    '        Next

    '        Dim x = parameterstring
    '    End If

    'End Sub

    Protected Sub InsertTargetListODS_Inserting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles InsertTargetListODS.Inserting
        e.InputParameters("EntityId") = CType(DropDownList1.SelectedValue, Integer?)
        e.InputParameters("Name") = txtName.Text
        e.InputParameters("MsgRef") = Nothing
        e.InputParameters("BillingRef") = Nothing
        e.InputParameters("ListTypeId") = CType(ddllkpListType.SelectedValue, Byte?)
        e.InputParameters("Note") = txtNote.Text
        e.InputParameters("SingleUse") = True
        e.InputParameters("DateCreated") = DateTime.Now
        e.InputParameters("AutoDiscarded") = True
        e.InputParameters("DateDiscarded") = True
        e.InputParameters("Active") = True
        'GridView1.DataBind()
        ' UpdatePanel1.Update()
    End Sub

    Protected Sub InsertTargetListODS_Inserted(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles InsertTargetListODS.Inserted
        Dim justinsertedid As Integer
        justinsertedid = CInt(e.OutputParameters("TargetListId"))
        'Response.Redirect("~/private/secure_members/manage/Mytargetlist.aspx?u=" & DropDownList1.SelectedValue)
        ' DropDownList1.DataBind()
        'GridView1.DataBind().
        'Dim selection = DropDownList2.SelectedValue

        DropDownList2.DataBind()
        DropDownList2.SelectedValue = CStr(justinsertedid)
        BlankDetailsView()
        CreateColumnList()
        UpdatePanel1.Update()

        InsertPopupExtender.Hide()


    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        '        Dim isreadonly As PropertyInfo =
        'GetType(System.Collections.Specialized.NameValueCollection).GetProperty( _
        '"IsReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)

        '        ' make collection editable
        '        isreadonly.SetValue(Me.Request.QueryString, False, Nothing)
        '        If Not Request.QueryString("u") Is Nothing Then
        '            Request.QueryString.Remove("u")
        '        End If
        pnlSelectedColumns.Visible = False
        'GridView1.Visible = True

    End Sub

    Protected Sub btnCancel_Click(sender As Object, e As System.EventArgs) Handles btnCancel.Click
        InsertPopupExtender.Hide()
    End Sub

    'Protected Sub CheckBoxList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
    '    Dim si = CheckBoxList1.SelectedIndex
    '    Dim sv = CheckBoxList1.SelectedValue
    '    Dim dvf = CheckBoxList1.DataValueField
    '    Dim dtf = CheckBoxList1.DataTextField
    '    Dim sel = CheckBoxList1.Items.Item(si)
    '    If sel.Selected Then
    '        Dim insertcolumnTA As New LogginsLogDSTableAdapters.SPTableAdapter()
    '        insertcolumnTA.usp_TargetListSaveColumnList(CType(GridView1.SelectedValue, Integer?), dtf)
    '    Else

    '    End If

    'End Sub

    Protected Sub btnInsertCol_Click(sender As Object, e As System.EventArgs) Handles btnInsertCol.Click

        Try
            Dim parameterstring As String = String.Empty
            For Each row As GridViewRow In grdSelectedFields.Rows
                ' Access the CheckBox
                Dim columnname As String = grdSelectedFields.DataKeys(row.RowIndex).Value.ToString()
                Dim cb As CheckBox = CType(row.FindControl("chkboxFilled"), CheckBox)
                If cb IsNot Nothing AndAlso cb.Checked Then
                    parameterstring += "," + cb.Text
                    ''Dim newlkp As Integer = lkptargetlistcolumnlistTA.usp_lkp_TargetListColumnListInsert(cb.Text, True)
                    'targetlistcolumnlistTA.Insert(DropDownList1.SelectedValue, newlkp, True)
                End If
            Next


            If Not DropDownList2.SelectedValue Is Nothing Then
                If parameterstring.Count > 1 Then
                    Dim delall As New LogginsLogDSTableAdapters.SPTableAdapter()
                    delall.usp_TargetListColumnListDeleteByTargetListId(CInt(Label25.Text))

                    Dim savecolumnsTA As New LogginsLogDSTableAdapters.SPTableAdapter()
                    savecolumnsTA.usp_TargetListSaveColumnList(CType(Label25.Text, Integer?), parameterstring.Replace(" ", "").Remove(0, 1))

                Else
                    Label23.Text = "Please select atleast one column."

                End If

            Else
                Label23.Text = "Please select list from grid first"

            End If
        Catch ex As Exception
            Throw ex
        End Try
        Label27.Text = ""

        'Dim selection = DropDownList2.SelectedValue

        'DropDownList2.DataBind()
        'DropDownList2.SelectedValue = selection
        CreateColumnList()
        UpdatePanel1.Update()

        'pnlSelectedColumns.Visible = False

    End Sub

    'Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    '    pnlSelectedColumns.Visible = True

    'End Sub

    'Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
    '    txtName.Text = ""
    '    txtNote.Text = ""

    '    btnInsert.Visible = True
    '    btnUpdate.Visible = False
    '    'hdfSelectedId.Value = CStr(selectedID)
    '    InsertPopupExtender.Show()

    'End Sub


    Protected Sub btnDDLUpdate_Click(sender As Object, e As System.EventArgs) Handles btnDDLUpdate.Click
        Dim selectedID As Integer = CInt(DropDownList2.SelectedValue)
        Try
            'Dim selectedID As Integer = CInt(e.CommandArgument.ToString())
            Dim targetlistTA As New LogginsLogDSTableAdapters.usp_TargetListByIDTableAdapter()
            Dim targetlistDT As LogginsLogDS.usp_TargetListByIDDataTable
            targetlistDT = targetlistTA.GetData(selectedID)
            For Each targetlistRow As LogginsLogDS.usp_TargetListByIDRow In targetlistDT
                txtName.Text = targetlistRow.Name
                ddllkpListType.SelectedValue = CStr(targetlistRow.ListTypeId)
                txtNote.Text = targetlistRow.Note
                hdfSelectedId.Value = CStr(selectedID)
            Next
        Catch ex As Exception
            Throw ex
        End Try
        btnInsert.Visible = False
        btnUpdate.Visible = True
        InsertPopupExtender.Show()
    End Sub

    Protected Sub btnDDLInsert_Click(sender As Object, e As System.EventArgs) Handles btnDDLInsert.Click
        txtName.Text = ""
        txtNote.Text = ""

        btnInsert.Visible = True
        btnUpdate.Visible = False
        'hdfSelectedId.Value = CStr(selectedID)
        InsertPopupExtender.Show()
    End Sub

    Protected Sub btnDDLDelete_Click(sender As Object, e As System.EventArgs) Handles btnDDLDelete.Click
        Try
            Dim targetlistrecexpTA As New LogginsLogDSTableAdapters.usp_TargetListRecipient_ExpTableAdapter()
            Dim targetlistrecexpDT As LogginsLogDS.usp_TargetListRecipient_ExpDataTable
            targetlistrecexpDT = targetlistrecexpTA.GetData(Nothing)
            Dim targetlistrecexpentity = From t In targetlistrecexpDT.AsEnumerable() Where t.TargetListId = Convert.ToDouble(DropDownList2.SelectedValue) Select t


            For Each targetlistRow As LogginsLogDS.usp_TargetListRecipient_ExpRow In targetlistrecexpentity
                'Dim delrec As New LogginsLogDSTableAdapters.SPTableAdapter()
                'delrec.usp_Recipient_RecipientExtra_Delete(CType(targetlistRow.RecipientId, Byte?))

                targetlistrecexpTA.Delete(targetlistRow.Id)
            Next

        Catch ex As Exception
            Throw ex
        End Try
        SqlDataSource1.Delete()
        DropDownList2.DataBind()
    End Sub

    Protected Sub GridView2_DataBound(sender As Object, e As System.EventArgs) Handles GridView2.DataBound
        'If Not DropDownList2.SelectedValue = "" Then


        '    Dim colnamesTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
        '    Dim colnamesDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
        '    colnamesDT = colnamesTA.GetData(CType(DropDownList2.SelectedValue, Integer?))


        '    For index = 0 To 18
        '        For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnamesDT
        '            If GridView2.Columns(index).HeaderText = colnameRow.ColumnName Then
        '                GridView2.Columns(index).Visible = True
        '            Else
        '                GridView2.Columns(index).Visible = False
        '            End If
        '        Next



        '    Next
        'End If
        'Return
        'GridView2.Columns(1).Visible = False
        'GridView2.Columns(2).Visible = False
        'GridView2.Columns(3).Visible = False
        'GridView2.Columns(4).Visible = False
        'GridView2.Columns(5).Visible = False
        'GridView2.Columns(6).Visible = False
        'GridView2.Columns(7).Visible = False
        'GridView2.Columns(0).Visible = False
        'GridView2.Columns(1).Visible = False
        'GridView2.Columns(2).Visible = False
        'GridView2.Columns(3).Visible = False
    End Sub

    Protected Sub DetailsView1_DataBound(sender As Object, e As System.EventArgs) Handles DetailsView1.DataBound
        Dim CustomRefId As DetailsViewRow = DetailsView1.Rows(1)
        Dim FirstName As DetailsViewRow = DetailsView1.Rows(2)
        Dim LastName As DetailsViewRow = DetailsView1.Rows(3)
        Dim HomeEmailAddress As DetailsViewRow = DetailsView1.Rows(4)
        Dim WorkEmailAddress As DetailsViewRow = DetailsView1.Rows(5)
        Dim MobileNo As DetailsViewRow = DetailsView1.Rows(6)
        Dim DateAddedToList As DetailsViewRow = DetailsView1.Rows(7)
        Dim IsAdult As DetailsViewRow = DetailsView1.Rows(8)
        Dim Gender As DetailsViewRow = DetailsView1.Rows(9)
        Dim NI_Number As DetailsViewRow = DetailsView1.Rows(10)
        Dim SS_Number As DetailsViewRow = DetailsView1.Rows(11)
        Dim BirthMonth As DetailsViewRow = DetailsView1.Rows(12)
        Dim BirthDay As DetailsViewRow = DetailsView1.Rows(13)
        Dim BirthYear As DetailsViewRow = DetailsView1.Rows(14)
        Dim PostCode As DetailsViewRow = DetailsView1.Rows(15)
        Dim HouseNo As DetailsViewRow = DetailsView1.Rows(16)
        Dim OccupationNote As DetailsViewRow = DetailsView1.Rows(17)
        Dim IsLocal As DetailsViewRow = DetailsView1.Rows(18)


        CustomRefId.Visible = False
        FirstName.Visible = False
        LastName.Visible = False
        HomeEmailAddress.Visible = False
        WorkEmailAddress.Visible = False
        MobileNo.Visible = False
        DateAddedToList.Visible = False
        IsAdult.Visible = False
        Gender.Visible = False
        NI_Number.Visible = False
        SS_Number.Visible = False
        BirthMonth.Visible = False
        BirthDay.Visible = False
        BirthYear.Visible = False
        PostCode.Visible = False
        HouseNo.Visible = False
        OccupationNote.Visible = False
        IsLocal.Visible = False


    End Sub


    Protected Sub Button4_Click(sender As Object, e As System.EventArgs) Handles Button4.Click

        Dim checkdate As Boolean = True

        Dim cCustomRefId As TextBox = TryCast(DetailsView1.FindControl("TextBox1"), TextBox)
        Dim cFirstName As TextBox = TryCast(DetailsView1.FindControl("TextBox2"), TextBox)
        Dim cLastName As TextBox = TryCast(DetailsView1.FindControl("TextBox3"), TextBox)
        Dim cHomeEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox4"), TextBox)
        Dim cWorkEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox5"), TextBox)
        Dim cMobileNo As TextBox = TryCast(DetailsView1.FindControl("TextBox6"), TextBox)
        Dim cDateAddedToList As TextBox = TryCast(DetailsView1.FindControl("TextBox7"), TextBox)
        Dim cIsAdult As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
        Dim cGender As TextBox = TryCast(DetailsView1.FindControl("TextBox8"), TextBox)
        Dim cNI_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox9"), TextBox)
        Dim cSS_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox10"), TextBox)
        Dim cBirthMonth As TextBox = TryCast(DetailsView1.FindControl("TextBox11"), TextBox)
        Dim cBirthDay As TextBox = TryCast(DetailsView1.FindControl("TextBox12"), TextBox)
        Dim cBirthYear As TextBox = TryCast(DetailsView1.FindControl("TextBox13"), TextBox)
        Dim cPostCode As TextBox = TryCast(DetailsView1.FindControl("TextBox14"), TextBox)
        Dim cHouseNo As TextBox = TryCast(DetailsView1.FindControl("TextBox15"), TextBox)
        Dim cOccupationNote As TextBox = TryCast(DetailsView1.FindControl("TextBox16"), TextBox)
        Dim cIsLocal As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)

        Try

        Catch ex As Exception
            Throw ex
        End Try

        Dim colnamesTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
        Dim colnamesDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
        colnamesDT = colnamesTA.GetData(CType(DropDownList2.SelectedValue, Integer?))

        For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnamesDT
            If cCustomRefId.Visible Then
                txtCustomRefId = cCustomRefId.Text
            Else
                txtCustomRefId = ""
            End If
            If cFirstName.Visible Then
                txtFirstName = cFirstName.Text
                Label27.Text = ""

            Else
                txtFirstName = ""
                'Label27.Text = "First name must be selected"
                'Return
            End If
            If cLastName.Visible Then
                txtLastName = cLastName.Text

            Else
                txtLastName = ""
            End If
            If cHomeEmailAddress.Visible Then
                txtHomeEmailAddress = cHomeEmailAddress.Text

            Else
                txtHomeEmailAddress = ""
            End If
            If cWorkEmailAddress.Visible Then
                txtWorkEmailAddress = cWorkEmailAddress.Text
            Else
                txtWorkEmailAddress = ""
            End If
            If cMobileNo.Visible Then
                txtMobileNo = cMobileNo.Text

            Else
                txtMobileNo = ""
            End If
            If cDateAddedToList.Visible Then
                txtDateAddedToList = cDateAddedToList.Text

            Else
                txtDateAddedToList = CStr(DateTime.Now)
            End If
            If cIsAdult.Visible Then
                txtIsAdult = cIsAdult.Checked

            Else
                txtIsAdult = False
            End If
            If cGender.Visible Then
                txtGender = cGender.Text
            Else
                txtGender = ""
            End If
            If cNI_Number.Visible Then
                txtNI_Number = cNI_Number.Text
            Else
                txtNI_Number = ""
            End If
            If cSS_Number.Visible Then
                txtSS_Number = cSS_Number.Text
            Else
                txtSS_Number = ""
            End If
            If cBirthMonth.Visible Then
                If cBirthMonth.Text = "" Then
                    txtBirthMonth = CByte(1)
                Else
                    txtBirthMonth = CByte(cBirthMonth.Text)
                End If
            Else
                txtBirthMonth = 1
            End If
            If cBirthDay.Visible Then
                If cBirthDay.Text = "" Then
                    txtBirthDay = CByte(1)
                Else
                    txtBirthDay = CByte(cBirthDay.Text)
                End If

            Else
                txtBirthDay = 1
            End If
            If cBirthYear.Visible Then
                If cBirthYear.Text = "" Then
                    txtBirthYear = CByte(1)
                Else
                    txtBirthYear = CByte(cBirthYear.Text)
                End If
            Else
                txtBirthYear = 1
            End If
            If cPostCode.Visible Then
                txtPostCode = cPostCode.Text
            Else
                txtPostCode = ""
            End If
            If cHouseNo.Visible Then
                txtHouseNo = cHouseNo.Text
            Else
                txtHouseNo = ""
            End If
            If cOccupationNote.Visible Then
                txtOccupationNote = cOccupationNote.Text
            Else
                txtOccupationNote = ""
            End If
            If cIsLocal.Visible Then
                txtIsLocal = cIsLocal.Checked
            Else
                txtIsLocal = False
            End If
        Next
        'Dim returnedID As Integer
        Dim contact As Boolean = False

        If cFirstName.Visible AndAlso cFirstName.Text = String.Empty Then
            'Label27.Text = "Please enter first name"
            'Return
        End If

        If cHomeEmailAddress.Text = String.Empty AndAlso cWorkEmailAddress.Text = String.Empty AndAlso cMobileNo.Text = String.Empty Then
            Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
            Return
        Else
            If Not cHomeEmailAddress.Text = String.Empty Then
                If Not CheckEmail(cHomeEmailAddress.Text) Then


                    Label27.Text = "Please enter valid Home Email Address."
                    Return
                End If
            End If
            If Not cWorkEmailAddress.Text = String.Empty Then
                If Not CheckEmail(cWorkEmailAddress.Text) Then
                    Label27.Text = "Please enter valid Work Email Address."
                    Return
                End If
            End If

            contact = True
        End If

        If contact Then
            'Dim rec_recinsertTA As New LogginsLogDSTableAdapters.SPTableAdapter()
            'Dim newrecid = rec_recinsertTA.usp_RecipientInsert(txtCustomRefId, _
            '                                                   txtFirstName, _
            '                                                    txtLastName, _
            '                                                    txtHomeEmailAddress, _
            '                                                    txtWorkEmailAddress, _
            '                                                    txtMobileNo, _
            '                                                    DateTime.Now, _
            '                                                    True, _
            '                                                    CType(returnedID, Integer?))



            'Dim rec_recextinsertTA As New LogginsLogDSTableAdapters.usp_RecipientExtraTableAdapter()
            'Dim rec_recextinsertTA As New LogginsLogDSTableAdapters.SPTableAdapter()
            'rec_recextinsertTA.Insert(CType(newrecid, Integer?), _
            '                                            txtIsAdult, _
            '                                            txtGender, _
            '                                            txtNI_Number, _
            '                                            txtSS_Number, _
            '                                            txtBirthMonth, _
            '                                            txtBirthDay, _
            '                                            txtBirthYear, _
            '                                            txtPostCode, _
            '                                            txtHouseNo, _
            '                                            txtOccupationNote, _
            '                                            txtIsLocal, _
            '                                            True)

            Dim rec_recinsertTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByTargetListIdTableAdapter()
            Dim newnum As Integer
            Dim newnuma = rec_recinsertTA.usp_RecipientInsert(txtCustomRefId, _
                                        txtFirstName, _
                                        txtLastName, _
                                        txtHomeEmailAddress, _
                                        txtWorkEmailAddress, _
                                        txtMobileNo, _
                                        DateTime.Now, _
                                        True, _
                                        txtIsAdult, _
                                        txtGender, _
                                        txtNI_Number, _
                                        txtSS_Number, _
                                        txtBirthMonth, _
                                        txtBirthDay, _
                                        CType(txtBirthYear, Byte?), _
                                        txtPostCode, _
                                        txtHouseNo, _
                                        txtOccupationNote, _
                                        txtIsLocal, _
                                        CType(newnum, Integer?)
                                        )


            Dim targetlistcolumnlistinsertTA As New LogginsLogDSTableAdapters.usp_TargetListRecipient_ExpTableAdapter()
            targetlistcolumnlistinsertTA.Insert((CType(DropDownList2.SelectedValue, Integer?)), CType(newnuma, Integer?), True)

            'Dim targetlistexpinsTA As New LogginsLogDSTableAdapters.usp_TargetListRecipient_ExpTableAdapter()
            'targetlistexpinsTA.Insert((CType(DropDownList2.SelectedValue, Integer?)), CType(newnum, Integer?), True)

            Label27.Text = ""
            BlankDetailsView()
            CreateColumnList()
            ModalPopupExtender1.Hide()
            UpdatePanel2.DataBind()
            GridView2.DataBind()

        Else
            Label27.Text = "Please select your Home Email Address and/or Work Email Address and/or Mobile No"
            If cHomeEmailAddress.Text = String.Empty OrElse cWorkEmailAddress.Text = String.Empty OrElse cMobileNo.Text = String.Empty Then
                Label27.Text = "Please select your Home Email Address and/or Work Email Address and/or Mobile No"
                Return
            Else
            End If

            Return
        End If





    End Sub
    Function CheckEmail(ByRef emailstring As String) As Boolean
        Dim validemail As Boolean = False
        Dim n As New Regex("(?<user>[^@]+)@(?<host>.+)")
        Dim v As Match = n.Match(emailstring)
        If v.Success Then
            validemail = True

        End If

        Return v.Success
    End Function


    Protected Sub Button3_Click(sender As Object, e As System.EventArgs) Handles Button3.Click
        Button4.Visible = True
        Button8.Visible = False
        Button9.Visible = False
        BlankDetailsView()
        CreateColumnList()
        updSaveColumns.Update()
        UpdatePanel1.Update()

        ModalPopupExtender1.Show()
    End Sub

    Protected Sub btnCloseSecondPopUp_Click(sender As Object, e As System.EventArgs) Handles btnCloseSecondPopUp.Click
        ModalPopupExtender1.Hide()

    End Sub


    Protected Sub ObjectDataSource3_Selected(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource3.Selected
        'e.OutputParameters("RRId") = RecInsertedId
        e.OutputParameters("NewRecipientId") = RecInsertedId
        Label19.Text = CStr(e.OutputParameters("NewRecipientId"))
    End Sub

    Protected Sub GridView2_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView2.SelectedIndexChanged
        Dim cCustomRefId As TextBox = TryCast(DetailsView1.FindControl("TextBox1"), TextBox)
        Dim cFirstName As TextBox = TryCast(DetailsView1.FindControl("TextBox2"), TextBox)
        Dim cLastName As TextBox = TryCast(DetailsView1.FindControl("TextBox3"), TextBox)
        Dim cHomeEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox4"), TextBox)
        Dim cWorkEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox5"), TextBox)
        Dim cMobileNo As TextBox = TryCast(DetailsView1.FindControl("TextBox6"), TextBox)
        Dim cDateAddedToList As TextBox = TryCast(DetailsView1.FindControl("TextBox7"), TextBox)
        Dim cIsAdult As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
        Dim cGender As TextBox = TryCast(DetailsView1.FindControl("TextBox8"), TextBox)
        Dim cNI_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox9"), TextBox)
        Dim cSS_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox10"), TextBox)
        Dim cBirthMonth As TextBox = TryCast(DetailsView1.FindControl("TextBox11"), TextBox)
        Dim cBirthDay As TextBox = TryCast(DetailsView1.FindControl("TextBox12"), TextBox)
        Dim cBirthYear As TextBox = TryCast(DetailsView1.FindControl("TextBox13"), TextBox)
        Dim cPostCode As TextBox = TryCast(DetailsView1.FindControl("TextBox14"), TextBox)
        Dim cHouseNo As TextBox = TryCast(DetailsView1.FindControl("TextBox15"), TextBox)
        Dim cOccupationNote As TextBox = TryCast(DetailsView1.FindControl("TextBox16"), TextBox)
        Dim cIsLocal As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
        BlankDetailsView()
        GridView2.DataBind()
        Try
            Dim recipientseditTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByIdTableAdapter()
            Dim recipientseditDT As LogginsLogDS.usp_RecipientSelectByIdDataTable
            recipientseditDT = recipientseditTA.GetData(CType(GridView2.SelectedValue, Integer?))
            For Each recRow As LogginsLogDS.usp_RecipientSelectByIdRow In recipientseditDT

                If Not recRow.IsCustomRefIdNull Then
                    cCustomRefId.Text = CStr(recRow.CustomRefId)
                End If
                If Not recRow.IsFirstNameNull Then
                    cFirstName.Text = CStr(recRow.FirstName)
                End If
                If Not recRow.IsLastNameNull Then
                    cLastName.Text = CStr(recRow.LastName)
                End If
                If Not recRow.IsHomeEmailAddressNull Then
                    cHomeEmailAddress.Text = CStr(recRow.HomeEmailAddress)
                End If
                If Not recRow.IsWorkEmailAddressNull Then
                    cWorkEmailAddress.Text = CStr(recRow.WorkEmailAddress)
                End If
                If Not recRow.IsMobileNoNull Then
                    cMobileNo.Text = CStr(recRow.MobileNo)
                End If
                If Not recRow.IsDateAddedToListNull Then
                    cDateAddedToList.Text = CStr(recRow.DateAddedToList)
                End If

                cDateAddedToList.Text = CStr(recRow.DateAddedToList)

                If Not recRow.IsIsAdultNull Then
                    cIsAdult.Checked = recRow.IsAdult
                End If
                If Not recRow.IsGenderNull Then
                    cGender.Text = recRow.Gender

                End If
                If Not recRow.IsNI_NumberNull Then
                    cNI_Number.Text = recRow.NI_Number

                End If

                If Not recRow.IsSS_NumberNull Then
                    cSS_Number.Text = recRow.SS_Number

                End If
                If Not recRow.IsBirthMonthNull Then
                    cBirthMonth.Text = recRow.BirthMonth.ToString()

                End If
                If Not recRow.IsBirthDayNull Then
                    cBirthDay.Text = recRow.BirthDay.ToString()

                End If

                If Not recRow.IsBirthYearNull Then
                    cBirthYear.Text = recRow.BirthYear.ToString()
                End If

                If Not recRow.IsPostCodeNull Then
                    cPostCode.Text = recRow.PostCode

                End If

                If Not recRow.IsHouseNoNull Then
                    cHouseNo.Text = recRow.HouseNo
                End If

                If Not recRow.IsOccupationNoteNull Then
                    cOccupationNote.Text = recRow.OccupationNote

                End If
                If Not recRow.IsIsLocalNull Then
                    cIsLocal.Checked = recRow.IsLocal
                End If

            Next

        Catch ex As Exception
            Throw ex
        End Try
        'Label20.Text = CStr(GridView2.SelectedValue)
        HiddenField1.Value = CStr(GridView2.SelectedValue)
        Button4.Visible = False
        Button8.Visible = True
        Button9.Visible = True
        GridView2.DataBind()
        ModalPopupExtender1.Show()
        UpdatePanel1.Update()
    End Sub

    Protected Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click
        Dim cCustomRefId As TextBox = TryCast(DetailsView1.FindControl("TextBox1"), TextBox)
        Dim cFirstName As TextBox = TryCast(DetailsView1.FindControl("TextBox2"), TextBox)
        Dim cLastName As TextBox = TryCast(DetailsView1.FindControl("TextBox3"), TextBox)
        Dim cHomeEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox4"), TextBox)
        Dim cWorkEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox5"), TextBox)
        Dim cMobileNo As TextBox = TryCast(DetailsView1.FindControl("TextBox6"), TextBox)
        Dim cDateAddedToList As TextBox = TryCast(DetailsView1.FindControl("TextBox7"), TextBox)
        Dim cIsAdult As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
        Dim cGender As TextBox = TryCast(DetailsView1.FindControl("TextBox8"), TextBox)
        Dim cNI_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox9"), TextBox)
        Dim cSS_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox10"), TextBox)
        Dim cBirthMonth As TextBox = TryCast(DetailsView1.FindControl("TextBox11"), TextBox)
        Dim cBirthDay As TextBox = TryCast(DetailsView1.FindControl("TextBox12"), TextBox)
        Dim cBirthYear As TextBox = TryCast(DetailsView1.FindControl("TextBox13"), TextBox)
        Dim cPostCode As TextBox = TryCast(DetailsView1.FindControl("TextBox14"), TextBox)
        Dim cHouseNo As TextBox = TryCast(DetailsView1.FindControl("TextBox15"), TextBox)
        Dim cOccupationNote As TextBox = TryCast(DetailsView1.FindControl("TextBox16"), TextBox)
        Dim cIsLocal As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)

        Dim contact As Boolean = False

        If cFirstName.Visible AndAlso cFirstName.Text = String.Empty Then
            'Label27.Text = "Please enter first name"
            'Return
        End If
        If cHomeEmailAddress.Text = String.Empty AndAlso cWorkEmailAddress.Text = String.Empty AndAlso cMobileNo.Text = String.Empty Then
            Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
            Return
        Else
            If Not cHomeEmailAddress.Text = String.Empty Then
                If Not CheckEmail(cHomeEmailAddress.Text) Then


                    Label27.Text = "Please enter valid Home Email Address."
                    Return
                End If
            End If
            If Not cWorkEmailAddress.Text = String.Empty Then
                If Not CheckEmail(cWorkEmailAddress.Text) Then
                    Label27.Text = "Please enter valid Work Email Address."
                    Return
                End If
            End If

            contact = True
        End If

        'If cHomeEmailAddress.Visible AndAlso Not contact Then
        'If Not contact Then
        '    If cHomeEmailAddress.Text = String.Empty Then
        '        contact = False
        '        Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '        Return

        '    End If

        '    If Not contact Then
        '        contact = True
        '    End If
        '    'Else
        '    '    contact = False
        '    '    Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '    '    Return

        'End If
        '' If cWorkEmailAddress.Visible AndAlso Not contact Then
        'If Not contact Then
        '    If cWorkEmailAddress.Text = String.Empty Then
        '        Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '        Return

        '    End If

        '    If Not contact Then
        '        contact = True
        '    End If
        '    'Else
        '    '    contact = False
        '    '    Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '    '    Return

        'End If
        ''If cMobileNo.Visible AndAlso Not contact Then
        'If Not contact Then
        '    If cMobileNo.Text = String.Empty Then
        '        Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '        Return

        '    End If

        '    If Not contact Then
        '        contact = True
        '    End If
        '    'Else
        '    '    contact = False
        '    '    Label27.Text = "Please select your Home Email Address and/or Work Email Address and/or Mobile No"
        '    '    Return

        'End If
        If contact Then

            'recipientseditTA.Update(CType(GridView2.SelectedValue, Integer?), cCustomRefId.Text, cFirstName.Text, cLastName.Text, cHomeEmailAddress.Text, cWorkEmailAddress.Text, cMobileNo.Text, CType(cDateAddedToList.Text, Date?), True)
            'recipientsexteditTA.Update(CType(GridView2.SelectedValue, Integer?), cIsAdult.Checked, cGender.Text, cNI_Number.Text, cSS_Number.Text, CType(cBirthMonth.Text, Byte?), CType(cBirthDay.Text, Byte?), CShort(cBirthYear.Text), cPostCode.Text, cHouseNo.Text, cOccupationNote.Text, cIsLocal.Checked, True)
            Try
                Dim recipientseditTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByTargetListIdTableAdapter()
                Dim updatedid As Integer = 0
                recipientseditTA.Update(CType(GridView2.SelectedValue, Integer?), cCustomRefId.Text, cFirstName.Text, cLastName.Text, cHomeEmailAddress.Text, cWorkEmailAddress.Text, cMobileNo.Text, CType(cDateAddedToList.Text, Date?), True, cIsAdult.Checked, cGender.Text, cNI_Number.Text, cSS_Number.Text, CType(cBirthMonth.Text, Byte?), CType(cBirthDay.Text, Byte?), CType(cBirthYear.Text, Byte?), cPostCode.Text, cHouseNo.Text, cOccupationNote.Text, cIsLocal.Checked, CType(updatedid, Integer?))

            Catch ex As Exception
                Throw ex
            End Try
            BlankDetailsView()
            GridView2.DataBind()
            ModalPopupExtender1.Hide()


        Else
            Label27.Text = "Please select your Home Email Address and/or Work Email Address and/or Mobile No"

        End If

        'If cFirstName.Visible AndAlso cFirstName.Text = String.Empty Then
        '    Label27.Text = "Please enter your firstname"
        'Else
        '    If cHomeEmailAddress.Visible AndAlso cHomeEmailAddress.Text = String.Empty AndAlso cWorkEmailAddress.Visible AndAlso cWorkEmailAddress.Text = String.Empty AndAlso cMobileNo.Visible AndAlso cMobileNo.Text = String.Empty Then
        '        Label27.Text = "Please enter your Home Email Address and/or Work Email Address and/or Mobile No"
        '    Else
        '        Try
        '            recipientseditTA.Update(CType(GridView2.SelectedValue, Integer?), cCustomRefId.Text, cFirstName.Text, cLastName.Text, cHomeEmailAddress.Text, cWorkEmailAddress.Text, cMobileNo.Text, CType(cDateAddedToList.Text, Date?), True)
        '            recipientsexteditTA.Update(CType(GridView2.SelectedValue, Integer?), cIsAdult.Checked, cGender.Text, cNI_Number.Text, cSS_Number.Text, CType(cBirthMonth.Text, Byte?), CType(cBirthDay.Text, Byte?), CShort(cBirthYear.Text), cPostCode.Text, cHouseNo.Text, cOccupationNote.Text, cIsLocal.Checked, True)

        '        Catch ex As Exception
        '            Throw ex
        '        End Try
        '        BlankDetailsView()
        '        GridView2.DataBind()
        '        ModalPopupExtender1.Hide()

        '    End If

        'End If

    End Sub

    Protected Sub Button9_Click(sender As Object, e As System.EventArgs) Handles Button9.Click
        'Dim recipientseditTA As New LogginsLogDSTableAdapters.usp_RecipientsTableAdapter()
        'Dim recipientsexteditTA As New LogginsLogDSTableAdapters.usp_RecipientExtraTableAdapter()
        'recipientseditTA.Delete(CType(GridView2.SelectedValue, Integer?))
        'recipientsexteditTA.Delete(CType(GridView2.SelectedValue, Integer?))
        Try
            Dim targetlistrecexpTA As New LogginsLogDSTableAdapters.usp_TargetListRecipient_ExpTableAdapter()
            Dim targetlistrecexpDT As LogginsLogDS.usp_TargetListRecipient_ExpDataTable
            targetlistrecexpDT = targetlistrecexpTA.GetData(Nothing)
            Dim targetlistrecexpentity = From t In targetlistrecexpDT.AsEnumerable() Where t.TargetListId = Convert.ToDouble(DropDownList2.SelectedValue) AndAlso t.RecipientId = Convert.ToInt32(GridView2.SelectedValue) Select t


            For Each targetlistRow As LogginsLogDS.usp_TargetListRecipient_ExpRow In targetlistrecexpentity
                'Dim delrec As New LogginsLogDSTableAdapters.SPTableAdapter()
                'delrec.usp_Recipient_RecipientExtra_Delete(CType(targetlistRow.RecipientId, Byte?))

                targetlistrecexpTA.Delete(targetlistRow.Id)
                Dim rec_deleteTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByTargetListIdTableAdapter()
                rec_deleteTA.Delete(targetlistRow.RecipientId)

            Next
        Catch ex As Exception
            Throw ex
        End Try
        BlankDetailsView()
        GridView2.DataBind()
        ModalPopupExtender1.Hide()
    End Sub
    Sub BlankDetailsView()


        Dim cCustomRefId As TextBox = TryCast(DetailsView1.FindControl("TextBox1"), TextBox)
        Dim cFirstName As TextBox = TryCast(DetailsView1.FindControl("TextBox2"), TextBox)
        Dim cLastName As TextBox = TryCast(DetailsView1.FindControl("TextBox3"), TextBox)
        Dim cHomeEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox4"), TextBox)
        Dim cWorkEmailAddress As TextBox = TryCast(DetailsView1.FindControl("TextBox5"), TextBox)
        Dim cMobileNo As TextBox = TryCast(DetailsView1.FindControl("TextBox6"), TextBox)
        Dim cDateAddedToList As TextBox = TryCast(DetailsView1.FindControl("TextBox7"), TextBox)
        Dim cIsAdult As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
        Dim cGender As TextBox = TryCast(DetailsView1.FindControl("TextBox8"), TextBox)
        Dim cNI_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox9"), TextBox)
        Dim cSS_Number As TextBox = TryCast(DetailsView1.FindControl("TextBox10"), TextBox)
        Dim cBirthMonth As TextBox = TryCast(DetailsView1.FindControl("TextBox11"), TextBox)
        Dim cBirthDay As TextBox = TryCast(DetailsView1.FindControl("TextBox12"), TextBox)
        Dim cBirthYear As TextBox = TryCast(DetailsView1.FindControl("TextBox13"), TextBox)
        Dim cPostCode As TextBox = TryCast(DetailsView1.FindControl("TextBox14"), TextBox)
        Dim cHouseNo As TextBox = TryCast(DetailsView1.FindControl("TextBox15"), TextBox)
        Dim cOccupationNote As TextBox = TryCast(DetailsView1.FindControl("TextBox16"), TextBox)
        Dim cIsLocal As CheckBox = TryCast(DetailsView1.FindControl("CheckBox1"), CheckBox)



        cCustomRefId.Text = String.Empty
        cFirstName.Text = String.Empty
        cLastName.Text = String.Empty
        cHomeEmailAddress.Text = String.Empty
        cWorkEmailAddress.Text = String.Empty
        cMobileNo.Text = String.Empty
        cDateAddedToList.Text = String.Empty
        cIsAdult.Checked = True
        cGender.Text = String.Empty
        cNI_Number.Text = String.Empty
        cSS_Number.Text = String.Empty
        cBirthMonth.Text = String.Empty
        cBirthDay.Text = String.Empty
        cBirthYear.Text = String.Empty
        cPostCode.Text = String.Empty
        cHouseNo.Text = String.Empty
        cOccupationNote.Text = String.Empty
        cIsLocal.Checked = True

    End Sub

    Protected Sub Button10_Click(sender As Object, e As System.EventArgs) Handles Button10.Click
        Try
            Dim targetlistrecexpTA As New LogginsLogDSTableAdapters.usp_TargetListRecipient_ExpTableAdapter()
            Dim targetlistrecexpDT As LogginsLogDS.usp_TargetListRecipient_ExpDataTable
            targetlistrecexpDT = targetlistrecexpTA.GetData(Nothing)
            Dim checkdupleucate = From t In targetlistrecexpDT.AsEnumerable() Where t.RecipientId = Convert.ToDouble(HiddenField1.Value) AndAlso t.TargetListId = Convert.ToDouble(DropDownList4.SelectedValue) Select t
            HiddenField1.Value = CStr(GridView2.SelectedValue)
            Dim newrec = CType(HiddenField1.Value, Integer?)
            Dim newlist = CType(DropDownList4.SelectedValue, Integer?)
            If checkdupleucate.Count = 0 Then
                If CDbl(RadioButtonList1.SelectedValue) = 0 Then


                    Dim recbyidTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByIdTableAdapter()
                    Dim recbyidDT As LogginsLogDS.usp_RecipientSelectByIdDataTable
                    recbyidDT = recbyidTA.GetData(newrec)
                    Dim newnum As Integer
                    For Each recRow As LogginsLogDS.usp_RecipientSelectByIdRow In recbyidDT

                        Dim rec_recinsertTA As New LogginsLogDSTableAdapters.usp_RecipientSelectByTargetListIdTableAdapter()

                        Dim CustomRefId As String
                        Dim FirstName As String
                        Dim LastName As String
                        Dim HomeEmailAddress As String
                        Dim WorkEmailAddress As String
                        Dim MobileNo As String
                        Dim IsAdult As Boolean
                        Dim Gender As String
                        Dim NI_Number As String
                        Dim SS_Number As String
                        Dim BirthMonth As Byte
                        Dim BirthDay As Byte
                        Dim BirthYear As Short
                        Dim PostCode As String
                        Dim HouseNo As String
                        Dim OccupationNote As String
                        Dim IsLocal As Boolean


                        If recRow.IsCustomRefIdNull Then
                            CustomRefId = String.Empty
                        Else
                            CustomRefId = recRow.CustomRefId
                        End If

                        If recRow.IsFirstNameNull Then
                            FirstName = String.Empty
                        Else
                            FirstName = recRow.FirstName
                        End If

                        If recRow.IsLastNameNull Then
                            LastName = String.Empty
                        Else
                            LastName = recRow.LastName
                        End If
                        If recRow.IsHomeEmailAddressNull Then
                            HomeEmailAddress = String.Empty
                        Else
                            HomeEmailAddress = recRow.HomeEmailAddress
                        End If
                        If recRow.IsWorkEmailAddressNull Then
                            WorkEmailAddress = String.Empty
                        Else
                            WorkEmailAddress = recRow.WorkEmailAddress
                        End If
                        If recRow.IsMobileNoNull Then
                            MobileNo = String.Empty
                        Else
                            MobileNo = recRow.MobileNo
                        End If
                        If recRow.IsIsAdultNull Then
                            IsAdult = False
                        Else
                            IsAdult = recRow.IsAdult
                        End If
                        If recRow.IsGenderNull Then
                            Gender = String.Empty
                        Else
                            Gender = recRow.Gender
                        End If
                        If recRow.IsNI_NumberNull Then
                            NI_Number = String.Empty
                        Else
                            NI_Number = recRow.NI_Number
                        End If
                        If recRow.IsSS_NumberNull Then
                            SS_Number = String.Empty
                        Else
                            SS_Number = recRow.SS_Number
                        End If
                        If recRow.IsBirthMonthNull Then
                            BirthMonth = 0
                        Else
                            BirthMonth = CByte(recRow.BirthMonth)
                        End If
                        If recRow.IsBirthDayNull Then
                            BirthDay = 0
                        Else
                            BirthDay = CByte(recRow.BirthDay)
                        End If
     
                        If recRow.IsBirthYearNull Then
                            BirthYear = 0
                        Else
                            BirthYear = CByte(recRow.BirthYear)
                        End If
                        If recRow.IsPostCodeNull Then
                            PostCode = String.Empty
                        Else
                            PostCode = recRow.PostCode
                        End If
                        If recRow.IsHouseNoNull Then
                            HouseNo = String.Empty
                        Else
                            HouseNo = recRow.HouseNo
                        End If
                        If recRow.IsOccupationNoteNull Then
                            OccupationNote = String.Empty
                        Else
                            OccupationNote = recRow.OccupationNote
                        End If
                        If recRow.IsIsLocalNull Then
                            IsLocal = False
                        Else
                            IsLocal = recRow.IsLocal
                        End If

                        Dim newnuma = rec_recinsertTA.usp_RecipientInsert(txtCustomRefId, _
                                                    txtFirstName, _
                                                    txtLastName, _
                                                    txtHomeEmailAddress, _
                                                    txtWorkEmailAddress, _
                                                    txtMobileNo, _
                                                    DateTime.Now, _
                                                    True, _
                                                    txtIsAdult, _
                                                    txtGender, _
                                                    txtNI_Number, _
                                                    txtSS_Number, _
                                                    txtBirthMonth, _
                                                    txtBirthDay, _
                                                    CType(txtBirthYear, Byte?), _
                                                    txtPostCode, _
                                                    txtHouseNo, _
                                                    txtOccupationNote, _
                                                    txtIsLocal, _
                                                    CType(newnum, Integer?)
                                                    )
                    Next





                    targetlistrecexpTA.Insert(newlist, newnum, True)
                Else
                    Dim getdelid = (From t In targetlistrecexpDT.AsEnumerable() Where t.RecipientId = Convert.ToDouble(HiddenField1.Value) AndAlso t.TargetListId = Convert.ToDouble(DropDownList2.SelectedValue) Select t).FirstOrDefault().Id
                    targetlistrecexpTA.Delete(getdelid)
                    targetlistrecexpTA.Insert(newlist, newrec, True)
                End If

            Else
                Label22.Text = "Recipient already exist in selected list"
            End If
        Catch ex As Exception
            Throw ex
        End Try
        GridView2.DataBind()

    End Sub
    Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        Label25.Text = DropDownList2.SelectedValue

        Dim colnamesTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
        Dim colnamesDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
        Try

            If Not Label25.Text = "" Then
                If Not Session("eid") Is Nothing AndAlso Not Session("lid") Is Nothing Then
                    btnDDLUpdate.Visible = False
                    btnDDLDelete.Visible = False
                Else
                    btnDDLUpdate.Visible = True
                    btnDDLDelete.Visible = True
                End If



                pnlSelectedColumns.Visible = True
                Button3.Visible = True
                'GridView2.DataSourceID = "ObjectDataSource1"
                'GridView2.DataBind()

                Button3.Visible = True
                colnamesDT = colnamesTA.GetData(CType(Label25.Text, Integer?))
                Dim i As Integer = 1
                For index = 0 To 19
                    GridView2.Columns(index).Visible = False
                Next
                For index = i To 19
                    For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnamesDT
                        If GridView2.Columns(index).HeaderText = colnameRow.ColumnName Then
                            GridView2.Columns(index).Visible = True
                        End If
                    Next

                    i = i + 1

                Next
                GridView2.Columns(0).Visible = True
            End If
        Catch ex As Exception
            Throw ex
        End Try

        Dim CustomRefId As DetailsViewRow = DetailsView1.Rows(1)
        Dim FirstName As DetailsViewRow = DetailsView1.Rows(2)
        Dim LastName As DetailsViewRow = DetailsView1.Rows(3)
        Dim HomeEmailAddress As DetailsViewRow = DetailsView1.Rows(4)
        Dim WorkEmailAddress As DetailsViewRow = DetailsView1.Rows(5)
        Dim MobileNo As DetailsViewRow = DetailsView1.Rows(6)
        Dim DateAddedToList As DetailsViewRow = DetailsView1.Rows(7)
        Dim IsAdult As DetailsViewRow = DetailsView1.Rows(8)
        Dim Gender As DetailsViewRow = DetailsView1.Rows(9)
        Dim NI_Number As DetailsViewRow = DetailsView1.Rows(10)
        Dim SS_Number As DetailsViewRow = DetailsView1.Rows(11)
        Dim BirthMonth As DetailsViewRow = DetailsView1.Rows(12)
        Dim BirthDay As DetailsViewRow = DetailsView1.Rows(13)
        Dim BirthYear As DetailsViewRow = DetailsView1.Rows(14)
        Dim PostCode As DetailsViewRow = DetailsView1.Rows(15)
        Dim HouseNo As DetailsViewRow = DetailsView1.Rows(16)
        Dim OccupationNote As DetailsViewRow = DetailsView1.Rows(17)
        Dim IsLocal As DetailsViewRow = DetailsView1.Rows(18)


        CustomRefId.Visible = False
        FirstName.Visible = False
        LastName.Visible = False
        HomeEmailAddress.Visible = False
        WorkEmailAddress.Visible = False
        MobileNo.Visible = False
        DateAddedToList.Visible = False
        IsAdult.Visible = False
        Gender.Visible = False
        NI_Number.Visible = False
        SS_Number.Visible = False
        BirthMonth.Visible = False
        BirthDay.Visible = False
        BirthYear.Visible = False
        PostCode.Visible = False
        HouseNo.Visible = False
        OccupationNote.Visible = False
        IsLocal.Visible = False
        Try
        Catch ex As Exception
            Throw ex
        End Try


        Dim colnameslistTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
        Dim colnameslistDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
        If Not DropDownList2.SelectedValue = "" Then
            If Not Session("eid") Is Nothing AndAlso Not Session("lid") Is Nothing Then
                btnDDLUpdate.Visible = False
                btnDDLDelete.Visible = False
            Else
                btnDDLUpdate.Visible = True
                btnDDLDelete.Visible = True
            End If
            pnlSelectedColumns.Visible = True
            Button3.Visible = True
            'GridView2.DataSourceID = "ObjectDataSource1"
            'GridView2.DataBind()

            Button3.Visible = True

            colnameslistDT = colnameslistTA.GetData(CType(Label25.Text, Integer?))

            For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnameslistDT
                If colnameRow.ColumnName = "CustomRefId" Then
                    CustomRefId.Visible = True
                End If
                If colnameRow.ColumnName = "FirstName" Then
                    FirstName.Visible = True
                End If
                If colnameRow.ColumnName = "LastName" Then
                    LastName.Visible = True
                End If
                If colnameRow.ColumnName = "HomeEmailAddress" Then
                    HomeEmailAddress.Visible = True
                End If
                If colnameRow.ColumnName = "WorkEmailAddress" Then
                    WorkEmailAddress.Visible = True
                End If
                If colnameRow.ColumnName = "MobileNo" Then
                    MobileNo.Visible = True
                End If
                If colnameRow.ColumnName = "DateAddedToList" Then
                    DateAddedToList.Visible = True
                End If
                If colnameRow.ColumnName = "IsAdult" Then
                    IsAdult.Visible = True
                End If
                If colnameRow.ColumnName = "Gender" Then
                    Gender.Visible = True
                End If
                If colnameRow.ColumnName = "NI_Number" Then
                    NI_Number.Visible = True
                End If
                If colnameRow.ColumnName = "SS_Number" Then
                    SS_Number.Visible = True
                End If
                If colnameRow.ColumnName = "BirthMonth" Then
                    BirthMonth.Visible = True
                End If
                If colnameRow.ColumnName = "BirthDay" Then
                    BirthDay.Visible = True
                End If
                If colnameRow.ColumnName = "BirthYear" Then
                    BirthYear.Visible = True
                End If
                If colnameRow.ColumnName = "PostCode" Then
                    PostCode.Visible = True
                End If
                If colnameRow.ColumnName = "HouseNo" Then
                    HouseNo.Visible = True
                End If
                If colnameRow.ColumnName = "OccupationNote" Then
                    OccupationNote.Visible = True
                End If
                If colnameRow.ColumnName = "IsLocal" Then
                    IsLocal.Visible = True
                End If
            Next
            Dim i As Integer = 1
            For index = 0 To 19
                GridView2.Columns(index).Visible = False
            Next
            For index = i To 19
                For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnameslistDT
                    If GridView2.Columns(index).HeaderText = colnameRow.ColumnName Then
                        GridView2.Columns(index).Visible = True
                    End If
                Next

                i = i + 1

            Next
            GridView2.Columns(0).Visible = True
            Label21.Text = DropDownList2.SelectedItem.Text
        Else
            btnDDLUpdate.Visible = False
            btnDDLDelete.Visible = False
            pnlSelectedColumns.Visible = False
            Button3.Visible = False

        End If
        GridView2.Visible = True

        updSaveColumns.Update()
        UpdatePanel1.Update()
    End Sub
    Sub CreateColumnList()
        Dim CustomRefId As DetailsViewRow = DetailsView1.Rows(1)
        Dim FirstName As DetailsViewRow = DetailsView1.Rows(2)
        Dim LastName As DetailsViewRow = DetailsView1.Rows(3)
        Dim HomeEmailAddress As DetailsViewRow = DetailsView1.Rows(4)
        Dim WorkEmailAddress As DetailsViewRow = DetailsView1.Rows(5)
        Dim MobileNo As DetailsViewRow = DetailsView1.Rows(6)
        Dim DateAddedToList As DetailsViewRow = DetailsView1.Rows(7)
        Dim IsAdult As DetailsViewRow = DetailsView1.Rows(8)
        Dim Gender As DetailsViewRow = DetailsView1.Rows(9)
        Dim NI_Number As DetailsViewRow = DetailsView1.Rows(10)
        Dim SS_Number As DetailsViewRow = DetailsView1.Rows(11)
        Dim BirthMonth As DetailsViewRow = DetailsView1.Rows(12)
        Dim BirthDay As DetailsViewRow = DetailsView1.Rows(13)
        Dim BirthYear As DetailsViewRow = DetailsView1.Rows(14)
        Dim PostCode As DetailsViewRow = DetailsView1.Rows(15)
        Dim HouseNo As DetailsViewRow = DetailsView1.Rows(16)
        Dim OccupationNote As DetailsViewRow = DetailsView1.Rows(17)
        Dim IsLocal As DetailsViewRow = DetailsView1.Rows(18)


        CustomRefId.Visible = False
        FirstName.Visible = False
        LastName.Visible = False
        HomeEmailAddress.Visible = False
        WorkEmailAddress.Visible = False
        MobileNo.Visible = False
        DateAddedToList.Visible = False
        IsAdult.Visible = False
        Gender.Visible = False
        NI_Number.Visible = False
        SS_Number.Visible = False
        BirthMonth.Visible = False
        BirthDay.Visible = False
        BirthYear.Visible = False
        PostCode.Visible = False
        HouseNo.Visible = False
        OccupationNote.Visible = False
        IsLocal.Visible = False
        Try

            Dim colnameslistTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
            Dim colnameslistDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
            If Not Label25.Text = "" Then
                If Not Session("eid") Is Nothing AndAlso Not Session("lid") Is Nothing Then
                    btnDDLUpdate.Visible = False
                    btnDDLDelete.Visible = False
                Else
                    btnDDLUpdate.Visible = True
                    btnDDLDelete.Visible = True
                End If
                pnlSelectedColumns.Visible = True
                Button3.Visible = True
                'GridView2.DataSourceID = "ObjectDataSource1"
                'GridView2.DataBind()

                Button3.Visible = True

                colnameslistDT = colnameslistTA.GetData(CType(Label25.Text, Integer?))

                For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnameslistDT
                    If colnameRow.ColumnName = "CustomRefId" Then
                        CustomRefId.Visible = True
                    End If
                    If colnameRow.ColumnName = "FirstName" Then
                        FirstName.Visible = True
                    End If
                    If colnameRow.ColumnName = "LastName" Then
                        LastName.Visible = True
                    End If
                    If colnameRow.ColumnName = "HomeEmailAddress" Then
                        HomeEmailAddress.Visible = True
                    End If
                    If colnameRow.ColumnName = "WorkEmailAddress" Then
                        WorkEmailAddress.Visible = True
                    End If
                    If colnameRow.ColumnName = "MobileNo" Then
                        MobileNo.Visible = True
                    End If
                    If colnameRow.ColumnName = "DateAddedToList" Then
                        DateAddedToList.Visible = True
                    End If
                    If colnameRow.ColumnName = "IsAdult" Then
                        IsAdult.Visible = True
                    End If
                    If colnameRow.ColumnName = "Gender" Then
                        Gender.Visible = True
                    End If
                    If colnameRow.ColumnName = "NI_Number" Then
                        NI_Number.Visible = True
                    End If
                    If colnameRow.ColumnName = "SS_Number" Then
                        SS_Number.Visible = True
                    End If
                    If colnameRow.ColumnName = "BirthMonth" Then
                        BirthMonth.Visible = True
                    End If
                    If colnameRow.ColumnName = "BirthDay" Then
                        BirthDay.Visible = True
                    End If
                    If colnameRow.ColumnName = "BirthYear" Then
                        BirthYear.Visible = True
                    End If
                    If colnameRow.ColumnName = "PostCode" Then
                        PostCode.Visible = True
                    End If
                    If colnameRow.ColumnName = "HouseNo" Then
                        HouseNo.Visible = True
                    End If
                    If colnameRow.ColumnName = "OccupationNote" Then
                        OccupationNote.Visible = True
                    End If
                    If colnameRow.ColumnName = "IsLocal" Then
                        IsLocal.Visible = True
                    End If
                Next
                Dim i As Integer = 1
                For index = 0 To 19
                    GridView2.Columns(index).Visible = False
                Next
                For index = i To 19
                    For Each colnameRow As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdRow In colnameslistDT
                        If GridView2.Columns(index).HeaderText = colnameRow.ColumnName Then
                            GridView2.Columns(index).Visible = True
                        End If
                    Next

                    i = i + 1

                Next
                GridView2.Columns(0).Visible = True
                Label21.Text = DropDownList2.SelectedItem.Text
            Else
                btnDDLUpdate.Visible = False
                btnDDLDelete.Visible = False
                pnlSelectedColumns.Visible = False
                Button3.Visible = False

            End If
        Catch ex As Exception
            Throw ex
        End Try
        Label25.Text = DropDownList2.SelectedValue
    End Sub

    Protected Sub DropDownList2_DataBound(sender As Object, e As System.EventArgs) Handles DropDownList2.DataBound

        'Dim colnamesTA As New LogginsLogDSTableAdapters.usp_GetTargetListColumnNamesByTargetListIdTableAdapter()
        'Dim colnamesDT As LogginsLogDS.usp_GetTargetListColumnNamesByTargetListIdDataTable
        'colnamesDT = colnamesTA.GetData(CType(DropDownList2.SelectedValue, Integer?))
        Label25.Text = DropDownList2.SelectedValue
        DropDownList4.DataBind()
        CreateColumnList()
        GridView2.Visible = True
        'UpdatePanel2.Update()
        If DropDownList2.Items.Count = 0 Then
            DropDownList2.Visible = False
        Else
            DropDownList2.Visible = True

        End If
        ' Label29.Text = DropDownList2.SelectedItem.Text


    End Sub


    Protected Sub DropDownList1_DataBound(sender As Object, e As System.EventArgs) Handles DropDownList1.DataBound
        If Not Page.IsPostBack Then
            DropDownList2.DataBind()
            DropDownList2.SelectedValue = Request.QueryString("lid")
        End If
        ' Label28.Text = DropDownList1.SelectedItem.Text
    End Sub


    Protected Sub Page_Unload(sender As Object, e As EventArgs) Handles Me.Unload
        If Session("EntityID") Is Nothing Then
            Session("EntityID") = DropDownList1.SelectedValue
        End If

    End Sub

    Protected Sub grdSelectedFields_DataBound(sender As Object, e As EventArgs) Handles grdSelectedFields.DataBound
        For Each row As GridViewRow In grdSelectedFields.Rows
            ' Access the CheckBox
            Dim columnname As String = grdSelectedFields.DataKeys(row.RowIndex).Value.ToString()
            Dim cb As CheckBox = CType(row.FindControl("chkboxFilled"), CheckBox)
            If cb IsNot Nothing Then
                If cb.Text = "FirstName" Then
                    cb.Text = "First Name"
                ElseIf cb.Text = "HomeEmailAddress" Then
                    cb.Text = "Home Email Address"
                ElseIf cb.Text = "WorkEmailAddress" Then
                    cb.Text = "Work Email Address"
                ElseIf cb.Text = "MobileNo" Then
                    cb.Text = "Mobile No"
                ElseIf cb.Text = "LastName" Then
                    cb.Text = "Last Name"
                ElseIf cb.Text = "DateAddedToList" Then
                    cb.Text = "Date Added To List"
                ElseIf cb.Text = "IsAdult" Then
                    cb.Text = "Is Adult"
                ElseIf cb.Text = "NI_Number" Then
                    cb.Text = "NI Number"
                ElseIf cb.Text = "SS_Number" Then
                    cb.Text = "SS Number"
                ElseIf cb.Text = "BirthMonth" Then
                    cb.Text = "Birth Month"
                ElseIf cb.Text = "BirthDay" Then
                    cb.Text = "Birth Day"
                ElseIf cb.Text = "BirthYear" Then
                    cb.Text = "Birth Year"
                ElseIf cb.Text = "PostCode" Then
                    cb.Text = "Post Code"
                ElseIf cb.Text = "HouseNo" Then
                    cb.Text = "House No"
                ElseIf cb.Text = "OccupationNote" Then
                    cb.Text = "Occupation Note"
                ElseIf cb.Text = "IsLocal" Then
                    cb.Text = "Is Local"
                End If

                'parameterstring += "," + cb.Text
                ''Dim newlkp As Integer = lkptargetlistcolumnlistTA.usp_lkp_TargetListColumnListInsert(cb.Text, True)
                'targetlistcolumnlistTA.Insert(DropDownList1.SelectedValue, newlkp, True)
            End If
        Next
        updSaveColumns.Update()
    End Sub
End Class
